<?php
/**
 * article table
 * 'title', 'short_title', 'descrition', 'image_id', 'image_id_list', 'content', 'uid'
 *
 */
namespace backend\models;

use Yii;
use yii\db\ActiveRecord;
class Goods extends ActiveRecord{
	public function scenarios(){
		return [
			'create' => ['name', 'cid', 'create_time', 'image_id', 'format', 'price', 'unit', 'status'],

			'update' => ['name', 'cid', 'image_id', 'format', 'price', 'unit'],
		];
	}

	public function rules(){

		return [
			[['name', 'cid'], 'required'],
			['name', 'string', 'min' => 1, 'max' => 50],
			['cid', 'exist', 'targetClass' => 'backend\models\Category', 'targetAttribute' => ['cid'=> 'id']],
			['image_id', 'exist', 'targetClass' => 'backend\models\Files', 'targetAttribute' => ['image_id'=> 'id']],
			['create_time', 'default', 'value' => time(), 'skipOnEmpty' => false,],
            ['article_id', 'exist', 'targetClass' => 'backend\models\Article', 'targetAttribute' => ['article_id'=> 'id']],
		    ['format', 'string', 'max' => 500],
            ['price', 'integer'],
            ['unit', 'in', 'range' => [10, 20, 30, 40, 50, 60, 70, 80]],
            ['status', 'default', 'value' => 1],
        ];
	}

    public function attributeLabels(){
        return [
            'name' => '商品名称',
            'image_id' => '商品封面',
            'image_id_list' => '商品图集',
            'cid' => '商品分类',
            'article_id' => '商品文章',
            'is_hot' => '是否热销',
            'is_advise' => '是否推荐',
            'format' => '规格选项(JSON)',
            'price' => '商品价格',
            'unit' => '单位',
        ];
    }
}